﻿<%@ Page Language="C#" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>
<%@ Import Namespace="TarreOA.TarreOAModels" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
    
    private PagedDataSource pds;
    private string start;
    private string end;

    protected void btnSerach_Click(object sender, EventArgs e)
    {
        this.SearchDataList_DatBind();
    }

    protected void SearchDataList_DatBind()
    {
        this.NewPagedDataSource();
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }
        this.start = this.txtStartDate.Text;
        this.end = this.txtEndDate.Text;
        this.DataList1_DataTable(start, end);
        this.DataList1_DataBind();
        ViewState["start"] = start;
        ViewState["end"] = end;
        ViewState["pg_in"] = pds.CurrentPageIndex;
    }

    private void NewPagedDataSource()
    {
        pds = new PagedDataSource();
        pds.AllowPaging = true;
        pds.PageSize = 5;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.btnSerach.Attributes.Add("onclick", "return checkRangeOfDate('" + this.txtStartDate.ClientID
                + "','" + this.txtEndDate.ClientID + "')");
            this.txtStartDate.Attributes.Add("onfocus", "calendar()");
            this.txtEndDate.Attributes.Add("onfocus", "calendar()");
            this.NewPagedDataSource();
            this.DataList1_DataTable("", "");
            this.DataList1_DataBind();
            ViewState["pg_in"] = pds.CurrentPageIndex;
            ViewState["start"] = this.txtStartDate.Text;
            ViewState["end"] = this.txtEndDate.Text;
        }
    }

    protected void DataList1_DataBind()
    {
        this.DataList1.DataSource = pds;
        this.DataList1.DataBind();
    }

    protected void DataList1_DataTable(string start, string end)
    {
        User curLoginUser = (User)Session["user"];
        UserDiarytbService userDiarytbService = new UserDiarytbService();
        List<UserDiary> list = userDiarytbService.findByUserLoginName(curLoginUser.LoginName);
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        if (list != null && list.Count > 0)
        {
            dt.Columns.Add("DiaryId", typeof(string));
            dt.Columns.Add("DiaryTitle", typeof(string));
            dt.Columns.Add("RegisterTime", typeof(string));
            foreach (UserDiary userDiary in list)
            {
                DataRow dr = dt.NewRow();
                if ("".Equals(start) && "".Equals(end))
                {
                    dr["DiaryId"] = userDiary.DiaryId.ToString();
                    dr["RegisterTime"] = userDiary.RegisterTime.ToString();
                    string diaryTitle = userDiary.DiaryTitle;
                    if (diaryTitle.Length > 26)
                    {
                        diaryTitle = diaryTitle.Substring(0, 26) + "...";
                    }
                    dr["DiaryTitle"] = diaryTitle;
                    dt.Rows.Add(dr);
                }
                else
                {
                    if (userDiary.RegisterTime >= DateTime.Parse(start) && userDiary.RegisterTime <= DateTime.Parse(end).AddDays(1))
                    {
                        dr["DiaryId"] = userDiary.DiaryId.ToString();
                        dr["RegisterTime"] = userDiary.RegisterTime.ToString();
                        string diaryTitle = userDiary.DiaryTitle;
                        if (diaryTitle.Length > 26)
                        {
                            diaryTitle = diaryTitle.Substring(0, 26) + "...";
                        }
                        dr["DiaryTitle"] = diaryTitle;
                        dt.Rows.Add(dr);
                    }
                }
            }
        }
        ds.Tables.Add(dt);
        pds.DataSource = ds.Tables[0].DefaultView;
    }

    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            if (pds.CurrentPageIndex == 0)
            {
                ((Button)e.Item.FindControl("btnGoTop")).Enabled = false;
                ((Button)e.Item.FindControl("btnRetu")).Enabled = false;
            }
            if (pds.CurrentPageIndex == pds.PageCount - 1)
            {
                ((Button)e.Item.FindControl("btnNext")).Enabled = false;
                ((Button)e.Item.FindControl("btnGoLast")).Enabled = false;
            }
        }
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            string did = ((HtmlInputHidden)e.Item.FindControl("diaryId")).Value;
            ((HyperLink)e.Item.FindControl("hplDiaryContent")).Target = "DiaryContentFrame";
            ((HyperLink)e.Item.FindControl("hplDiaryContent")).NavigateUrl = "DiaryContent.aspx?did=" + did;
        }
    }

    protected void btnGoTop_Click(object sender, EventArgs e)
    {
        if (ViewState["start"] != null && ViewState["end"] != null)
        {
            start = (string)ViewState["start"];
            end = (string)ViewState["end"];
        }
        this.NewPagedDataSource();
        this.DataList1_DataTable(start, end);
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }
        pds.CurrentPageIndex = 0;
        this.DataList1_DataBind();
        ViewState["start"] = start;
        ViewState["end"] = end;
        ViewState["pg_in"] = pds.CurrentPageIndex;
    }

    protected void btnRetu_Click(object sender, EventArgs e)
    {
        if (ViewState["start"] != null && ViewState["end"] != null)
        {
            start = (string)ViewState["start"];
            end = (string)ViewState["end"];
        }
        this.NewPagedDataSource();
        this.DataList1_DataTable(start, end);
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }
        pds.CurrentPageIndex--;
        this.DataList1_DataBind();
        ViewState["start"] = start;
        ViewState["end"] = end;
        ViewState["pg_in"] = pds.CurrentPageIndex;
    }

    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (ViewState["start"] != null && ViewState["end"] != null)
        {
            start = (string)ViewState["start"];
            end = (string)ViewState["end"];
        }
        this.NewPagedDataSource();
        this.DataList1_DataTable(start, end);
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }
        pds.CurrentPageIndex++;
        this.DataList1_DataBind();
        ViewState["start"] = start;
        ViewState["end"] = end;
        ViewState["pg_in"] = pds.CurrentPageIndex;
    }

    protected void btnGoLast_Click(object sender, EventArgs e)
    {
        if (ViewState["start"] != null && ViewState["end"] != null)
        {
            start = (string)ViewState["start"];
            end = (string)ViewState["end"];
        }
        this.NewPagedDataSource();
        this.DataList1_DataTable(start, end);
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }
        pds.CurrentPageIndex = pds.PageCount - 1;
        this.DataList1_DataBind();
        ViewState["start"] = start;
        ViewState["end"] = end;
        ViewState["pg_in"] = pds.CurrentPageIndex;
    }

    protected void btnDelMsg_Click(object sender, EventArgs e)
    {
        if (ViewState["start"] != null && ViewState["end"] != null)
        {
            start = (string)ViewState["start"];
            end = (string)ViewState["end"];
        }
        string[] dids = Request.Params.GetValues("chkCur");
        UserDiarytbService userDiarytbService = new UserDiarytbService();
        userDiarytbService.delDiaryInfoByDiaryId(dids);
        this.NewPagedDataSource();
        this.DataList1_DataTable(start, end);
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }
        int cp = pds.CurrentPageIndex;
        if (pds.PageCount == cp)
        {
            pds.CurrentPageIndex = pds.PageCount - 1;
        }
        else
        {
            pds.CurrentPageIndex = cp;
        }
        this.DataList1_DataBind();
        ViewState["start"] = start;
        ViewState["end"] = end;
        ViewState["pg_in"] = pds.CurrentPageIndex;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <link rel="Stylesheet" type="text/css" href="../../Styles/right_style.css" />
    <script type="text/javascript" src="../../js/MyOption.js"></script>
    <script type="text/javascript" src="../../Scripts/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
<!--
html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
-->
</style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="sub_right_top">
        <div class="hdm_footer">
            <!--我的日记-->
            <div id="tb1_1_content" class="cont01_word" style="display: block;">
                <div class="sub_work_plan">
                    <asp:Repeater ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
                        <HeaderTemplate>
                            <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="dataList"
                                align="center">
                                <tr class="jsmail_bgcolor">
                                    <td style="width: 20%;">
                                        <input id="chkAll" onclick="allMsgCheck('chkCur')" type="checkbox" />
                                    </td>
                                    <td style="width: 40%;">
                                        计划标题
                                    </td>
                                    <td style="width: 40%;">
                                        记录时间
                                    </td>
                                </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <input id="chkCur" name="chkCur" type="checkbox" value='<%# Eval("DiaryId") %>' />
                                </td>
                                <td>
                                    <asp:HyperLink ID="hplDiaryContent" runat="server" ForeColor="Teal" Text='<%# Eval("DiaryTitle") %>'></asp:HyperLink>
                                    <input id="diaryId" runat="server" type="hidden" value='<%# Eval("DiaryId") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="lblSendDateTime" runat="server" Text='<%# Eval("RegisterTime") %>'
                                        ForeColor="Teal" Width="122px"></asp:Label>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            <tr class="jsmail_bgcolor">
                                <td>
                                    <input id="chkAll" onclick="allMsgCheck('chkCur')" type="checkbox" />
                                </td>
                                <td colspan="2" align="right" style="border-left-width: 0;">
                                    <span style="float: left;">
                                        <asp:Button ID="btnDelMsg" runat="server" BorderStyle="Groove" OnClientClick="return checkDelMsg('chkCur')"
                                            Text="删除" Width="58px" OnClick="btnDelMsg_Click" />
                                    </span>
                                    <asp:Button ID="btnGoTop" runat="server" BorderStyle="Groove" Height="24px" Text="首页"
                                        Width="58px" OnClick="btnGoTop_Click" />
                                    &nbsp;
                                    <asp:Button ID="btnRetu" runat="server" BorderStyle="Groove" Text="上一页" OnClick="btnRetu_Click" />&nbsp;
                                    <asp:Button ID="btnNext" runat="server" BorderStyle="Groove" Text="下一页" OnClick="btnNext_Click" />
                                    <asp:Button ID="btnGoLast" runat="server" BorderStyle="Groove" Height="24px" Text="末页"
                                        Width="58px" OnClick="btnGoLast_Click" />
                                    <asp:Label ID="lblPageState" runat="server" Width="126px"></asp:Label>
                                </td>
                            </tr>
                            </table>
                        </FooterTemplate>
                    </asp:Repeater>
                    <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="dataList">
                        <tr>
                            <td align="left">
                                工作计划查询:&nbsp; 从&nbsp;<asp:TextBox ID="txtStartDate" runat="server" CssClass="Wdate"
                                    onClick="WdatePicker()"></asp:TextBox>&nbsp; 到&nbsp;<asp:TextBox ID="txtEndDate"
                                        runat="server" CssClass="Wdate" onClick="WdatePicker()"></asp:TextBox>&nbsp;
                                <asp:Button ID="btnSerach" runat="server" OnClick="btnSerach_Click" Text="查找" />
                            </td>
                        </tr>
                    </table>
                </div>
                <table cellpadding="0" cellspacing="0" align="center" width="100%">
                    <tr>
                        <td>
                            <iframe frameborder="0" name="DiaryContentFrame" scrolling="auto" src="WriteDiary.aspx"
                                style="width: 100%; height: 350px"></iframe>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    </form>
</body>
</html>
